package com.rd.student.jiaji.class3.wangyanbo.task24;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class TestExecutor1 {
    private static final int CORE_POOL_SIZE=5;
    private static final int MAX_POOL_SOZE=20;
    private static final int QUEUE_CAPACITY=2;
    private static final Long KEEP_ALIVE_TIME=1L;

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                CORE_POOL_SIZE,
                MAX_POOL_SOZE,
                KEEP_ALIVE_TIME,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(QUEUE_CAPACITY),
                new ThreadPoolExecutor.AbortPolicy());
        List<Future<String>> futureList=new ArrayList<>();
        MyCallable callable=new MyCallable();
        for (int i =0;i<12;i++){
            Future<String>future=executor.submit(callable);
            futureList.add(future);
        }
        for (Future<String> future:futureList){
            try{
                String result = future.get();
                System.out.println(result);
            }catch (InterruptedException | ExecutionException e){
                e.printStackTrace();
            }
        }
    }
}
